<?php get_instance()->view('common/header');?>
<!--<script src="--><?php //echo $this->staticUrl;?><!--plugins/dist/js/app.js" type="text/javascript"></script>-->
<style>
	.box.box-info {
		border-top-color: #e6e6e6;
	}
	.box-header.with-border {
		border-bottom: 1px solid #f4f4f4;
	}
	.box-body {
		border-top-left-radius: 0;
		border-top-right-radius: 0;
		border-bottom-right-radius: 3px;
		border-bottom-left-radius: 3px;
		padding: 10px;
	}
	.box-header {
		color: #444;
		display: block;
		padding: 10px;
		position: relative;
	}
	.box.box-primary {
		border-top-color: #e6e6e6;
	}
	.box {
		position: relative;
		border-radius: 3px;
		background: #ffffff;
		border-top: 3px solid #d2d6de;
		margin-bottom: 20px;
		width: 100%;
		box-shadow: 0 1px 1px rgba(0,0,0,0.1);
	}
    #list-table>thead>tr>th{text-align: center;}

</style>
<div class="page-container wrapper">
	<!-- BEGIN SIDEBAR -->
    <?php get_instance()->view('common/sidebar');?>
	<!-- END SIDEBAR -->
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content" style="min-height:1200px !important">
			<!-- BEGIN PAGE HEADER-->
			<div class="col-xs-12">
				<div class="">
                    <div class="row">
                        <div class="col-md-12">
                            <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                            <h3 class="page-title"> 销售运营表 </h3>
                            <ul class="page-breadcrumb breadcrumb">
                                <li><i class="fa fa-home"></i><a href="javascript:void(0);">销售运营表 </a></li>
                            </ul>
                            <!-- END PAGE TITLE & BREADCRUMB-->
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                            <div class="dashboard-stat blue">
                                <div class="visual">
                                    <img src="<?php echo $this->staticUrl;?>img/statistics1.png" alt="">
                                </div>
                                <div class="details">
                                    <div class="number reality_amount"><?php  echo $countAll['total_amount'] ?></div>
                                    <div class="desc">订单总额</div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                            <div class="dashboard-stat green">
                                <div class="visual">
                                    <img src="<?php echo $this->staticUrl;?>img/statistics2.png" alt="">
                                </div>
                                <div class="details">
                                    <div class="number total"><?php  echo $countAll['total'] ?></div>
                                    <div class="desc">总订单量</div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                            <div class="dashboard-stat purple">
                                <div class="visual">
                                    <img src="<?php echo $this->staticUrl;?>img/statistics3.png" alt="">
                                </div>
                                <div class="details">
                                    <div class="number expenditure"><?php  echo $countAll['discount_amount'] ?></div>
                                    <div class="desc">优惠金额</div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                            <div class="dashboard-stat yellow">
                                <div class="visual">
                                    <img src="<?php echo $this->staticUrl;?>img/statistics4.png" alt="">
                                </div>
                                <div class="details">
                                    <div class="number profit"><?php  echo $countAll['reality_amount'] ?></div>
                                    <div class="desc">用户实付</div>
                                </div>
                            </div>
                        </div>
                    </div>
					<div class="row">
						<div class="col-md-12">
							<div class="box box-info">
								<div class="box-header with-border">
									<div class="row">
										<div class="col-md-12">
											<form action="" method="post">
												<div class="col-xs-5">
													<div class="input-group margin">
														<div class="input-group-addon">
															选择时间  <i class="fa fa-calendar"></i>
														</div>
														<input type="text" class="form-control pull-right" name="timegap" value="<?php echo $startTime .' - '. $endTime?>" id="start_time">
													</div>
                                                    <span class="help-block">温馨提示：选择的时间范围请控制在三个月以内,若超过范围则自动计算时间</span>
												</div>
                                                <?php if(adminAuthority('sell-export', 'statistics')):?>
                                                    <div class="col-xs-2 col-xs-offset-3"><a class="btn btn-block export blue" href="javascript:;">导出</a></div>
                                                    <div class="col-xs-2 "><input class="btn btn-block btn-info green" type="submit" value="确定"></div>
                                                <?php else:?>
                                                    <div class="col-xs-2 col-xs-offset-5"><input class="btn btn-block btn-info green" type="submit" value="确定"></div>
                                                <?php endif;?>
											</form>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="box box-primary">
								<div class="box-header with-border">
									<h3 class="panel-title">销售走势</h3>
									<div class="box-tools"></div>
									<div class="box-tools pull-right" style="display: none">
										<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
										<button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
									</div>
								</div>
								<div class="box-body">
									<div class="chart" style="height: 400px;">
										<div id="statistics" style="height: 400px;"></div>
									</div>
								</div>
							</div>
						</div>
					</div>

					<div class="row">
						<div class="col-sm-12">
                            <ul class="nav nav-tabs" role="tablist">
                                <li role="presentation" class="active">
                                    <a href="#date" aria-controls="date" role="tab" data-toggle="tab"><i class="fa fa-list"></i>按日期统计</a>
                                </li>
                                <li role="presentation">
                                    <a href="#merchant" aria-controls="merchant" role="tab" data-toggle="tab"><i class="fa fa-list"></i>按商家统计</a>
                                </li>
                            </ul>

                            <!-- Tab panes -->
                            <div class="tab-content">
                                <div role="tabpanel" class="tab-pane active" id="date">
                                    <div class="panel panel-default">
                                        <div class="panel-body">
                                            <table id="date-table" class="table table-bordered table-striped">
                                                <thead role="row" class="heading">
                                                    <tr>
                                                        <th rowspan="2">日期</th>
                                                        <th colspan="2">订单总额</th>
                                                        <th colspan="3">优惠金额</th>
                                                        <th rowspan="2">实付金额</th>
                                                        <th rowspan="2">订单数</th>
                                                        <th rowspan="2">下单用户数</th>
                                                        <th rowspan="2">退差价</th>
                                                        <th rowspan="2">客单价</th>
                                                        <th rowspan="2">售后订单量</th>
                                                        <th rowspan="2">售后总额</th>
                                                        <th rowspan="2">查看</th>
                                                    </tr>
                                                    <tr>
                                                        <th>商品总额</th>
                                                        <th>配送费</th>
                                                        <th>平台红包</th>
                                                        <th>包邮卡</th>
                                                        <th>商家优惠</th>
                                                    </tr>
                                                </thead>
                                                <tbody>

                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                                <div role="tabpanel" class="tab-pane" id="merchant">
                                    <div class="panel panel-default">
                                        <div class="panel-body">
                                            <table id="merchant-table" class="table table-bordered table-striped">
                                                <thead role="row" class="heading">
                                                <tr>
                                                    <th rowspan="2">商家</th>
                                                    <th colspan="2">订单总额</th>
                                                    <th colspan="3">优惠金额</th>
                                                    <th rowspan="2">实付金额</th>
                                                    <th rowspan="2">订单数</th>
                                                    <th rowspan="2">下单用户数</th>
                                                    <th rowspan="2">退差价</th>
                                                    <th rowspan="2">客单价</th>
                                                    <th rowspan="2">售后订单量</th>
                                                    <th rowspan="2">售后总额</th>
                                                    <th rowspan="2">查看</th>
                                                </tr>
                                                <tr>
                                                    <th>商品总额</th>
                                                    <th>配送费</th>
                                                    <th>平台红包</th>
                                                    <th>包邮卡</th>
                                                    <th>商家优惠</th>
                                                </tr>
                                                </thead>
                                                <tbody>

                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
						</div>
					</div>
                    <div class="row"></div>
				</div>
			</div>
            <div style="clear: both"></div>
		</div>
	</div>
</div>
<!-- END CONTENT -->
</div>
<script type="text/javascript">
	var res = <?php echo $result?>;
	var startTime = <?php echo $startTime?>;
	var endTime = <?php echo $endTime?>;
	var myChart = echarts.init(document.getElementById('statistics'),'macarons');
	option = {
		tooltip : {
			trigger: 'axis'
		},
		legend: {
			data:['订单总量','订单总额','优惠金额','用户实付']
		},
		xAxis : [
			{
				type : 'category',
				data : res.time
			}
		],
		yAxis : [
			{
				type : 'value',
				name : '数量',
				axisLabel : {
					formatter: '{value}'
				}
			},
			{
				type : 'value',
				name : '金额',
				axisLabel : {
					formatter: '{value} ￥'
				}
			}
		],
		series : [
			{
				name:'订单总量',
				type:'line',
				data:res.order
			},
			{
				name:'订单总额',
				type:'bar',
                yAxisIndex: 1,
				data:res.total_amount
			},
			{
				name:'优惠金额',
				type:'bar',
				yAxisIndex: 1,
				data:res.discount_amount
			},
			{
				name:'用户实付',
				type:'bar',
				yAxisIndex: 1,
				data:res.reality_amount
			}
		]
	};
	myChart.setOption(option);
        
	$(document).ready(function() {
		$('#start_time').daterangepicker({
			format:"YYYY-MM-DD",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2016-01-01',
            maxDate: moment(new Date()), //设置最大日期
			startDate:'<?php echo $startTime?>',
            endDate: '<?php echo $endTime?>', //设置结束器日期
			showWeekNumbers: true,
			timePicker: false,
			timePickerIncrement: 1,
			timePicker12Hour: true,
			ranges: {
				'今天': [moment(), moment()],
				'昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
				'最近7天': [moment().subtract('days', 6), moment()],
				'最近30天': [moment().subtract('days', 29), moment()],
				'上一个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
			},
			opens: 'right',
			buttonClasses: ['btn btn-default'],
			applyClass: 'btn-small btn-primary',
			cancelClass: 'btn-small',
			locale : {
				applyLabel : '确定',
				cancelLabel : '取消',
				fromLabel : '起始时间',
				toLabel : '结束时间',
				customRangeLabel : '自定义',
				daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
				monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
				firstDay : 1
			}
		});
	});

	$(function () {
        datatable_init({
            src: $("#date-table"),
            sAjaxSource: "<?php echo getUrl('statistics/operate/statisticsDateList?endTime='.$endTime.'&startTime='.$startTime);?>",
            aoColumnDefs : [{
                'bSortable' : false,
                'aTargets' : [0,1,2,3,4,5,6,7,8,9,10,11,12,13]
            }]
        });
        datatable_init({
            src: $("#merchant-table"),
            sAjaxSource: "<?php echo getUrl('statistics/operate/getOperateStatisticsMerchantList?endTime='.$endTime.'&startTime='.$startTime);?>",
            aoColumnDefs : [{
                'bSortable' : false,
                'aTargets' : [0,1,2,3,4,5,6,7,8,9,10,11,12,13]
            }]
        });

        $(".export").click(function () {
            var time = $("[name='timegap']").val();
            window.location.href = "<?php echo getUrl('statistics/operate/export?time=')?>"+time
        })
    })
</script>
</body>
</html>